package com.example.opengldemo.vertex_magical.shader.filter;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLES30;
import android.opengl.GLUtils;

import com.example.opengldemo.R;
import com.example.opengldemo.util.TextureUtil;
import com.example.opengldemo.vertex_magical.shader.BaseRenderer;

public class FilterRenderer extends BaseRenderer {
    public static volatile int isOpen = 1 ;
    public static volatile float luminance = 0.1f ;

    public static volatile float uf_MagTol = 0.2f ;
    public static volatile float uf_Quantize = 18f ;

    public static volatile float[][] matrix3x3 = new float[3][3] ;
    public FilterRenderer(Resources resource, String vertex, String fragment) {
        super(resource, vertex, fragment);
    }

    private int markTextureId = -1;
    @Override
    protected void onCreate() {
        super.onCreate();
        shaderHandle.UHandleArray[0] =  shaderHandle.getUHandle("bSelect")  ;

        shaderHandle.UHandleArray[1] =  shaderHandle.getUHandle("uf_LeftTop")  ;
        shaderHandle.UHandleArray[2] =  shaderHandle.getUHandle("uf_CenterTop")  ;
        shaderHandle.UHandleArray[3] =  shaderHandle.getUHandle("uf_RightTop")  ;

        shaderHandle.UHandleArray[4] =  shaderHandle.getUHandle("uf_LeftCenter")  ;
        shaderHandle.UHandleArray[5] =  shaderHandle.getUHandle("uf_CenterCenter")  ;
        shaderHandle.UHandleArray[6] =  shaderHandle.getUHandle("uf_RightCenter")  ;

        shaderHandle.UHandleArray[7] =  shaderHandle.getUHandle("uf_LeftBottom")  ;
        shaderHandle.UHandleArray[8] =  shaderHandle.getUHandle("uf_CenterBottom")  ;
        shaderHandle.UHandleArray[9] =  shaderHandle.getUHandle("uf_RightBottom")  ;

        shaderHandle.UHandleArray[10] =  shaderHandle.getUHandle("uf_ScaleFactor")  ;

        shaderHandle.UHandleArray[11] =  shaderHandle.getUHandle("uf_MagTol")  ;
        shaderHandle.UHandleArray[12] =  shaderHandle.getUHandle("uf_Quantize")  ;

    }


    @Override
    protected void onSetExpandData() {
        super.onSetExpandData();
        GLES30.glUniform1i(shaderHandle.UHandleArray[0] , isOpen);

        GLES30.glUniform1f(shaderHandle.UHandleArray[1] , matrix3x3[0][0]);
        GLES30.glUniform1f(shaderHandle.UHandleArray[2] , matrix3x3[0][1]);
        GLES30.glUniform1f(shaderHandle.UHandleArray[3] , matrix3x3[0][2]);

        GLES30.glUniform1f(shaderHandle.UHandleArray[4] , matrix3x3[1][0]);
        GLES30.glUniform1f(shaderHandle.UHandleArray[5] , matrix3x3[1][1]);
        GLES30.glUniform1f(shaderHandle.UHandleArray[6] , matrix3x3[1][2]);

        GLES30.glUniform1f(shaderHandle.UHandleArray[7] , matrix3x3[2][0]);
        GLES30.glUniform1f(shaderHandle.UHandleArray[8] , matrix3x3[2][1]);
        GLES30.glUniform1f(shaderHandle.UHandleArray[9] , matrix3x3[2][2]);



        GLES30.glUniform1f(shaderHandle.UHandleArray[10] , luminance);

        GLES30.glUniform1f(shaderHandle.UHandleArray[11] , uf_MagTol);
        GLES30.glUniform1f(shaderHandle.UHandleArray[12] , uf_Quantize);
    }

}
